package com.plian.system.enumeratea;

import com.plian.spring.SpringUtil;
import com.plian.system.service.fr.adjustment.IAdjustmentService;
import com.plian.system.service.fr.annualreport.IAnnualReportService;
import com.plian.system.service.fr.authorize.IAuthorizeService;
import com.plian.system.service.fr.bulletin.INewBulletinService;
import com.plian.system.service.fr.payrolladjustment.IPayrollAdjustmentService;
import com.plian.system.service.fr.report.IReportService;
import com.plian.system.service.yth.IYthDataTransferService;
import com.plian.system.vo.yth.YthExcelInfoVO;
import lombok.Getter;
import org.springframework.web.multipart.MultipartFile;

import java.util.function.BiFunction;

import static com.plian.system.constant.sys.FormTypeConstant.*;

@Getter
public enum YthExcelTransferEnum {

    TEST(0, -1, SpringUtil.getBean(IYthDataTransferService.class)::excelTest),
    //工资总额预算
    SALARY_BUDGET(1, FR_PAYROLL_ADJUSTMENT, SpringUtil.getBean(IPayrollAdjustmentService.class)::ythBudgetExcelUpload),
    //工资总额预算调整
    SALARY_BUDGET_ADJUSTMENT(2,  FR_PAYROLL_ADJUSTMENT, SpringUtil.getBean(IPayrollAdjustmentService.class)::ythAdjustExcelUpload),
    //五项费用管理预算（不对接  包含在预算里）
    FIVE_EXPENSE_BUDGET(3, FR_BULLETIN, SpringUtil.getBean(IYthDataTransferService.class)::excelTest),
    //快报
    BULLETIN(4, FR_BULLETIN, SpringUtil.getBean(INewBulletinService.class)::ythExcelUpload),
    //年报
    ANNUAL_REPORT(5, FR_ANNUALREPORT, SpringUtil.getBean(IAnnualReportService.class)::ythExcelUpload),
    //全面预算
    BUDGET(6, GSALARY_SLIP_FORM, SpringUtil.getBean(IReportService.class)::ythExcelUpload),
    //全面预算调整
    BUDGET_ADJUSTMENT(7, FR_BUDGET_ADJUSTMENT, SpringUtil.getBean(IAdjustmentService.class)::ythExcelUpload),
    //预算 审定
    APPROVAL(8, FR_BUDGET_AUTHORIZE, SpringUtil.getBean(IAuthorizeService.class)::ythExcelUpload);


    private int excelType;

    private int formType;

    private BiFunction<YthExcelInfoVO, MultipartFile, String> function;

    YthExcelTransferEnum(int excelType, int formType, BiFunction<YthExcelInfoVO, MultipartFile, String>  function){
        this.excelType = excelType;
        this.formType = formType;
        this.function = function;
    }

    public static int getExcelTypeByFormType(int formType) {
        for (YthExcelTransferEnum value : YthExcelTransferEnum.values()){
            if (formType == value.formType){
                return value.excelType;
            }
        }
        return -1;
    }

    public static YthExcelTransferEnum getByExcelType(int excelType){
        for (YthExcelTransferEnum value : YthExcelTransferEnum.values()){
            if (excelType == value.excelType){
                return value;
            }
        }
        return null;
    }

    public static BiFunction<YthExcelInfoVO, MultipartFile, String> getFunction(int excelType){
        for (YthExcelTransferEnum value : YthExcelTransferEnum.values()){
            if (excelType == value.excelType){
                return value.function;
            }
        }
        return null;
    }
}
